package com.atguigu.gulimall.product.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyRedissonConfig {

    /**
     * 所有对redisson的使用都是通过RedissonClient对象
     * @return
     */
    @Bean(destroyMethod = "shutdown")
    public RedissonClient redisson() {
        // 1.创建配置
        Config config = new Config();
        // 集群redis
//        config.useClusterServers().addNodeAddress("redis://10.211.55.10:6379",
//                "redis://10.211.55.10:6380","redis://10.211.55.10:6381","redis://10.211.55.10:6389",
//                "redis://10.211.55.10:6390","redis://10.211.55.10:6391");

        // rediss:// or redis://
        // 单机redis
        config.useSingleServer().setAddress("redis://42.193.120.56:6379");
        // 2.更加config创建出RedissonClient
        RedissonClient redissonClient = Redisson.create(config);
        return redissonClient;
    }
}
